import { Controller, Get, Put, Body, UseGuards, Request } from '@nestjs/common';
import { UserService } from './user.service';
import { UpdateUserDto } from './dto/update-user.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';

@Controller('user')
@UseGuards(JwtAuthGuard)
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('profile')
  async getProfile(@Request() req) {
    const data = await this.userService.findById(req.user.id);
    return {
      code: 200,
      message: 'success',
      data,
      timestamp: Date.now(),
    };
  }

  @Put('profile')
  async updateProfile(@Request() req, @Body() updateUserDto: UpdateUserDto) {
    const data = await this.userService.update(req.user.id, updateUserDto);
    return {
      code: 200,
      message: '更新成功',
      data,
      timestamp: Date.now(),
    };
  }
}
